package demo09_BlockingQueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author kunkun
 * @className Test04_BlockingLimitTime
 * @Description 阻塞，超时停止
 * @date 2025/3/6 13:54
 */
public class Test04_BlockingLimitTime {

    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<Object> queue = new ArrayBlockingQueue<>(2);

        //1. 新增
        queue.offer("a",3, TimeUnit.SECONDS);
        queue.offer("b",3, TimeUnit.SECONDS);
        queue.offer("c",3, TimeUnit.SECONDS); //队列已满，超时停止

        //2. 移除
        System.out.println(queue.poll());
        System.out.println(queue.poll());
        System.out.println(queue.poll(3, TimeUnit.SECONDS));    //队空，超时停止


    }




}
